<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <title>广告管理</title>
    <base href="<%=basePath %>"/>
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" href="assets/bootstrap-fileinput/css/fileinput.css">
    <link rel="stylesheet" href="assets/bootstrap-fileinput/themes/explorer/theme.css">
    <link rel="stylesheet" href="assets/layui/css/layui.css">
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/jquery.validator.min.js"></script>
    <script src="assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="assets/bootstrap-fileinput/js/fileinput.js"></script>
    <script src="assets/bootstrap-fileinput/js/locales/zh.js"></script>
    <script src="assets/bootstrap-fileinput/themes/explorer/theme.js"></script>
    <script src="assets/layui/layui.all.js"></script>

</head>
<body>
<div class="container" id="addModal">
    <%--<div class="modal-body" style="overflow:auto">
        <form id="addForm" class=" form-horizontal col-lg-offset-2">
            <table>
                <tr>
                    <td>选择文件：</td>
                    <td>
                        <input type="file" name="fish_file" id="fish_file" class="file-loading" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div class="modal-footer">
        <a class="btn-primary btn-sm" onclick="add()">添加</a>
    </div>--%>
    <div class="modal-body">
        <%--<div style="text-align:right;padding:5px">
            <a href="~/Content/Template/TestUser-模板.xls" onclick="javascript:Preview();">
                <img alt="测试用户信息-模板" src="~/Content/images/ico_excel.png" />
                <span style="font-size:larger;font-weight:200;color:red">TestUser-模板.xls</span>
            </a>
        </div>--%>
        <hr/>
        <form id="ffImport" method="post">
            <div title="Excel导入操作" style="padding: 5px">
                <input type="hidden" id="AttachGUID" name="AttachGUID"/>
                <input type="file" name="upfile" id="upfile"  class="file-loading"/>
            </div>
        </form>

        <!--数据显示表格-->
            <span class="col-lg-10 col-lg-offset-1" id="reshint" style="color: red" ></span>
        <table id="gridImport" class="table table-striped table-bordered table-hover" cellpadding="0" cellspacing="0"
               border="0">
        </table>
    </div>
   <%-- <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" onclick="SaveImport()">保存</button>
    </div>--%>
</div>

</body>
</html>
<script>

    $(document).ready(function () {
        layui.use('laydate', function () {
            var laydate = layui.laydate;
            //执行一个laydate实例
            laydate.render({
                elem: '#date1'//指定元素
            });
            //执行一个laydate实例
            laydate.render({
                elem: '#date2'//指定元素
            });
        });
        //0.初始化fileinput
        var oFileInput = new FileInput();
        oFileInput.Init("upfile", "detail/upload.action");
    });


    function add() {
        if (nonEmpty('advertName', "广告名")) {
            if (nonEmpty('date1', "起始时间")) {
                if (nonEmpty('date2', "结束时间")) {
                    //上传时间
                    $('#fish_file').fileinput('upload');
                }
            }
        }
    }

    //前端非空验证（标签ID，提示语）
    function nonEmpty(input, tips) {
        var inputval = $("#" + input).val();
        if (!inputval) {
            layer.tips('请输入' + tips + '!', '#' + input, {tips: [2, '#CC3333']});
            return false;
        }
        return true;
    }

    //关闭模态框后
    $('#detailsModal').on('hidden.bs.modal', function () {
        getAdverts(1);
    })
    $('#addModal').on('hidden.bs.modal', function () {
        getAdverts(1);
        $('#abbreviation').val(null);
        $('#content').val(null);
    })
    //初始化fileinput
    var FileInput = function () {
        var oFile = new Object();
        //初始化fileinput控件（第一次初始化）
        oFile.Init = function (ctrlName, uploadUrl) {
            var control = $('#' + ctrlName);
            //初始化上传控件的样式
            control.fileinput({
                language: 'zh', //设置语言
                uploadUrl: uploadUrl, //上传的地址
                allowedFileExtensions: ['xlsx', 'xls'],//接收的文件后缀
                showUpload: true, //是否显示上传按钮
                showCaption: true,//是否显示标题
                showPreview:false,
                browseClass: "btn btn-primary", //按钮样式
                dropZoneEnabled: false,//是否显示拖拽区域
                //minImageWidth: 50, //图片的最小宽度
                //minImageHeight: 50,//图片的最小高度
                //maxImageWidth: 1000,//图片的最大宽度
                //maxImageHeight: 1000,//图片的最大高度
                //maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
                //minFileCount: 0,
                maxFileCount: 1, //表示允许同时上传的最大文件个数
                enctype: 'multipart/form-data',
                validateInitialCount: true,
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                // msgFilesTooMany: "最多只能上传({n}) 超过允许的最大数值{m}！",
                msgFilesTooMany: "一次只能上传{m}个文件！",
                layoutTemplates: {
                    // actionDelete:'', //去除上传预览的缩略图中的删除图标
                    actionUpload: '',//去除上传预览缩略图中的上传图片；
                    //actionZoom:''   //去除上传预览缩略图中的查看详情预览的缩略图标。
                },
            });
            //导入文件上传完成之后的事件
            $("#upfile").on("fileuploaded", function (event, data, previewId, index) {
                var result = data.response; //后台返回的json
                var res='导入成功'+result.successNum;
                if (result.errorNum>0) {
                    res+='，失败'+result.errorNum+'，以下细项添加失败：';
                }
                $("#reshint").text(res);
                if(result.errList.length>0){

                    $('#gridImport').append(
                        "<thead> <tr><td>细项名称</td><td>项目名称</td><td>单位</td><td>最小值</td><td>最大值</td></tr></thead>"
                    );
                    var str = "<tbody>";
                    for(var i=0;i<result.errList.length;i++){
                        str+="<tr>";
                       for(var j=0;j<result.errList[i].length;j++){
                           str+="<td>"+result.errList[i][j]+"</td>";
                       }
                        str+="</tr>";
                    }
                    str+="</tbody>";
                    $('#gridImport').append(str);
                }
            });
        }
        return oFile;
    };


</script>